#include <thread>
#include <iostream>
#include <future>
int main()
{
    std::future<int> f1 = std::async(std::launch::async, []()
                                     {
        // while (1)
        // {
        //     std::this_thread::sleep_for(std::chrono::seconds(1));
        // }
        //std::this_thread::sleep_for(std::chrono::seconds(1));
        return 10; });
    // 主线程阻塞一秒
    std::future_status fstatus = f1.wait_for(std::chrono::seconds(1));
    // 主线程阻塞等待，等待子线程共享就绪
    // f1.wait();
    do
    {
        switch (fstatus)
        {
        case std::future_status::timeout:
            std::cout << "timeout" << std::endl;
            break;
        case std::future_status::deferred:
            std::cout << "deferred" << std::endl;
        default:
            break;
        }

    } while (fstatus != std::future_status::ready);

    std::cout << f1.get() << std::endl;

    return 0;
}